//
//  TXFWelcomeController.swift
//  weibo飞飞
//
//  Created by 田侠飞 on 16/6/26.
//  Copyright © 2016年 田侠飞. All rights reserved.
//

import UIKit
import SDWebImage
class TXFWelcomeController: UIViewController {

    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
       
        self.heatImageView.snp_updateConstraints { (make) -> Void in
           make.top.equalTo(self.view).offset(100)
        }
        
       UIView.animateWithDuration(3, delay: 1, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: { () -> Void in
          self.view.layoutIfNeeded()
        }) { (_) -> Void in
            
            UIView.animateWithDuration(0.25, animations: { () -> Void in
                self.messageLab.alpha = 1
                }, completion: { (_) -> Void in
              
                    
                    NSNotificationCenter.defaultCenter().postNotificationName(SwitchRootVcNotification, object:"welcome")
            })
            
        }
        
        
    }

    
   

    
    //创建控件:
    override  func loadView() {
        
        view = bigImage
      
        
        
    }
    override func viewDidLoad() {
        super.viewDidLoad()
          setupUI()
        
        
    }
    private func setupUI(){
    
        view.addSubview(heatImageView)
        view.addSubview(messageLab)
      
       
        heatImageView.snp_makeConstraints { (make) -> Void in
            make.size.equalTo(CGSize(width: 90, height: 90))
            make.top.equalTo(view).offset(400)
            make.centerX.equalTo(view)
        }

        
        
        messageLab.snp_makeConstraints { (make) -> Void in
            
            make.centerX.equalTo(view)
            
            make.top.equalTo(heatImageView.snp_bottom).offset(16)
            
        }
    
    
    }
      
     //设置动画
   
    
    
    
    private  lazy var bigImage : UIImageView = UIImageView(image: UIImage(named: "ad_background"))
    //创建头像:
    private lazy var heatImageView : UIImageView = {
    
    let img = UIImageView(image: UIImage(named: "avatar_default_big"))
    //把图裁剪成圆形并且加一个圆边
        
        img.layer.cornerRadius = 45
        
        img.layer.borderColor = UIColor.orangeColor().CGColor
   
        img.layer.borderWidth = 3
        
        img.layer.masksToBounds = true
        

        img.sd_setImageWithURL(NSURL(string: TXFUserAccountTools.sharedTools.userAccount?.avatar_large ?? " "), placeholderImage: UIImage(named: "ad_background"))
        
        
    return img
    }()
    
    private lazy var messageLab : UILabel = {
    
    let lab = UILabel()
    lab.textAlignment = .Center
        
    lab.textColor = UIColor.grayColor()

    lab.text = "欢迎回来"
        
    lab.font = UIFont.systemFontOfSize(20)
        
    lab.alpha = 0
    
    
    
    
    return lab
    
    }()
    
    
    
}
